package wangjg.coco.common;

import java.io.File;
import java.io.FileFilter;
import java.util.List;

/**
 * 文本文件字符编码转换器
 * 未实现...
 */
public class FileCharsetConverter {
	private FileFilter filter;

	/**
	 * 取得文件类型过滤器
	 */
	private FileFilter getFileFilter(final List<String> fileTypes) {
		return new FileFilter() {
			private String getType(File file) {
				String fileName = file.getName();
				int idx = (fileName==null? -1 : fileName.lastIndexOf('.'));
				if(idx > -1){
					return fileName.substring(idx+1);
				}
				return "";
			}

			public boolean accept(File file) {
				if (file.isHidden()){
					return false;
				}
				return file.isDirectory() || fileTypes.contains(getType(file))
						|| fileTypes.contains("*");
			}
		};
	}
	
	public void convert(File source, File target, String sourceCharset, String targetCharset){
		
	}
	
	public static void xx(File file){
		if(!file.canRead()){
			return;
		}
		if(file.isDirectory()){
			File[] list = file.listFiles();
			for(File f:list){
				xx(f);
			}
		}else if(file.isFile()){
			CharsetDetector.main(new String[]{file.getPath(),"UTF-8"});
		}
	}

	public static void main(String[] args) throws Exception {
		String dir = "E:\\wjg\\workspace\\eclipse\\wangjg\\src";
		File dirFile = new File(dir);
		xx(dirFile);
	}

}